import traceback

from fastapi import APIRouter, Depends

from app.api.response import Response, response_docs
from app.business.default_prompt import (
    DefaultPromptDetailBiz,
)
from app.api.status import Status
from app.initializer import g
from app.middleware.auth import JWTUser, get_current_user

default_prompt_router = APIRouter()


@default_prompt_router.get(
    path="/default_prompt/{default_prompt_id}",
    summary="default_promptDetail",
    responses=response_docs(
        model=DefaultPromptDetailBiz,
    ),
)
async def detail(
        default_prompt_id: str,
        current_user: JWTUser = Depends(get_current_user),
):
    try:
        default_prompt_biz = DefaultPromptDetailBiz(id=default_prompt_id)
        data = await default_prompt_biz.detail()
        if not data:
            return Response.failure(msg="未匹配到记录", status=Status.RECORD_NOT_EXIST_ERROR)
    except Exception as e:
        g.logger.error(traceback.format_exc())
        return Response.failure(msg="default_promptDetail失败", error=e)
    return Response.success(data=data)
